home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS02.ADF
/
Asm
/
qsortest.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-05-30
|
1KB
|
48 lines
/*
A program to test the qsort "quick-sort" procedure called from Lattice
Gary Sarff 12/07/85 Compuserve PPN: 70167,2216
Compile this program with something similar to
copy qtest.c to ram:
copy qsort.o to ram:
:c/lc1 -i:include/ -i:include/lattice/ ram:qtest
:c/lc2 ram:qtest
:c/alink :lib/lstartup.obj,ram:test.o,ram:qsort.o library
:lib/lc.lib,:lib/amiga.lib to ram:test map nil:
when you run qtest it should produce
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Sorting...
Finished
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
*/
#include <stdio.h>
extern qsort();
int array[] = {15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0}; /* test array */
int compfunc(first,second)
int *second,*first;
{
if ((*first) < (*second)) return(-1);
else
if ((*first) == (*second)) return 0;
else
if ((*first) > (*second)) return 1;
}
main()
{
int i;
unsigned int arsize;
arsize=sizeof(array)/sizeof(int);
for (i=0;i < arsize; i++)
printf("%d ",array[i]);
printf("\nSorting...\n");
qsort(&array[0],arsize,sizeof(int),compfunc);
printf("finished\n");
for (i=0;i < arsize; i++)
printf("%d ",array[i]);
printf("\n");
}